/*
 * Copyright (c) 2025 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

class AvoidArea {
  // Whether avoidArea is visible on screen
  // 规避区域是否可见。true表示可见；false表示不可见
  final bool visible;

  // Rectangle on the left of the screen
  // 屏幕左侧的矩形区
  final Rect leftRect;

  // Rectangle on the top of the screen
  // 屏幕顶部的矩形区
  final Rect topRect;

  // Rectangle on the right of the screen
  // 屏幕右侧的矩形区
  final Rect rightRect;

  // Rectangle on the bottom of the screen
  // 屏幕底部的矩形区
  final Rect bottomRect;

  AvoidArea({
    required this.visible,
    required this.leftRect,
    required this.topRect,
    required this.rightRect,
    required this.bottomRect,
  });

  factory AvoidArea.fromJson(Map<String, dynamic> parsedJson) {
    return AvoidArea(
        visible: parsedJson['visible'],
        leftRect: Rect.fromJson(parsedJson['leftRect']),
        topRect: Rect.fromJson(parsedJson['topRect']),
        rightRect: Rect.fromJson(parsedJson['rightRect']),
        bottomRect: Rect.fromJson(parsedJson['bottomRect']));
  }

  Map<String, dynamic> toJson() => <String, dynamic>{
        'visible': visible,
        'leftRect': leftRect.toJson(),
        'topRect': topRect.toJson(),
        'rightRect': rightRect.toJson(),
        'bottomRect': bottomRect.toJson(),
      };
}

enum AvoidAreaType {
  // Default area of the system
  // 系统默认区域。一般包括状态栏、导航栏
  system,
  // Notch
  // 刘海屏区域
  cutout,
  // Area for system gesture
  // 手势区域
  systemGesture,
  // Area for keyboard
  // 软键盘区域
  keyboard,
  // Area for navigation indicator
  // 导航条区域
  navigationIndicator;
}

// 窗口矩形区域
class Rect {
  // The left of the Rect.
  // 矩形区域的左边界，单位为px，该参数为整数
  final int left;

  // The top of the Rect.
  // 矩形区域的上边界，单位为px，该参数为整数
  final int top;

  // The width of the Rect.
  // 矩形区域的宽度，单位为px，该参数为整数
  final int width;

  // The height of the Rect.
  // 矩形区域的高度，单位为px，该参数为整数
  final int height;

  Rect({
    required this.left,
    required this.top,
    required this.width,
    required this.height,
  });

  factory Rect.fromJson(Map<String, dynamic> parsedJson) {
    return Rect(
        left: parsedJson['left'],
        top: parsedJson['top'],
        width: parsedJson['width'],
        height: parsedJson['height']);
  }

  Map<String, dynamic> toJson() => <String, dynamic>{
        'left': left,
        'top': top,
        'width': width,
        'height': height,
      };
}

class AvoidAreaOptions {
  // Avoid area type
  final AvoidAreaType type;

  // Avoid area
  final AvoidArea area;

  AvoidAreaOptions({required this.type, required this.area});

  factory AvoidAreaOptions.fromJson(Map<String, dynamic> parsedJson) {
    return AvoidAreaOptions(
        type: parsedJson['type'], area: AvoidArea.fromJson(parsedJson['area']));
  }
}
